// pages/phone/phone.js
Page({
  data: {
    phone: ""
  },
  onLoad: function (options) {
    var that = this;
    var session3rd = wx.getStorageSync("session3rd");
    wx.request({
      url: "https://myzhongchou.net/public/index.php/api/user/getphone",
      data: {
        session3rd: session3rd
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res);
        that.setData({
          phone: res.data.msg
        })
      }
    })
  },
  submit: function (e) {
    var that = this;
    var phones = e.detail.value.phone;
    var session3rd = wx.getStorageSync("session3rd");
    wx.request({
      url: "https://myzhongchou.net/public/index.php/api/user/insert_phone",
      methods: "post",
      data: {
        session3rd:session3rd,
        phone: phones
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res);
        if (res.data.success == 0) {
          wx.showToast({
            title: "成功",
            icon: "success"
          })
          wx.showToast({
            title: res.data.msg,
            icon: 'success',
            duration: 1500,
            success: function () {
              setTimeout(function () {
                wx.switchTab({
                  url: '../wode/wode'
                })
              }, 2000)
            }
          })
          
        } else if (res.data.error == 1) {
          wx.showToast({
            title: "号码格式错误",
            image: "../../img/gantan.png"
          })
        } else if (res.data.error == 2) {
          wx.showToast({
            title: "号码已存在",
            image: "../../img/gantan.png"
          })
        } else {
          wx.showToast({
            title: "网络错误，请重试",
            image: "../../img/gantan.png"
          })
        }
      }
    })
  }
})